#ifndef __QNET_H__
#define __QNET_H__
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>

#include <arpa/inet.h>
#include <net/if.h>
#include <sys/ioctl.h>
#include <sys/socket.h>

// 通过网口获取IP
int get_ip_address_from_interface(const char *ifName, char *ipAddr, int addr_len);

// 通过网口号获取mac
int get_mac_from_interface(const char *eth_inf, char *mac, int mac_len);

// 将mac字符串转为数值
int mac_to_array(const char *mac_addr, unsigned char *mac);


#if 0
void demo__get_ip_address_from_interface(void)
{
    char ip[64];
    char mac_string[64];
    unsigned char mac_bytes[6];
    const char *if = "eth0"
    int ret;
    int i;
    // 通过网口获取IP
    ret = get_ip_address_from_interface(if, ip, sizeof(ip));
    if(ret == 0)
    {
        printf("IP is %s\n", ip);
    } else
    {
        printf("get IP failed, ret = [%d] \n", ret);
    }
    // 通过网口获取MAC(字符串)
    ret = get_mac_from_interface(if, mac_string, sizeof(mac_string));
    if(ret == 0)
    {
        printf("mac is %s\n", mac_string);
    } else
    {
        printf("get mac failed, ret = [%d] \n", ret);
    }
    // 将mac字符串转为数值
    ret = mac_to_array(mac_string, mac_bytes, sizeof(mac_bytes));
#if 0
    for(i = 0; i < 6; i++)
    {
        printf("%02x \n", mac_bytes[i]);
    }
#endif
}
#endif

#endif
#endif/*__QNET_H__*/
